package com.study.mirrorforest.main.common.response;
import lombok.Data;
import lombok.ToString;
/**
 * @author liuha
 */
@ToString
@Data
public class R<T> {
    private Boolean success;
    private Integer code;
    private String message;
    private T data;
    private String accessToken;

    // 1. 带业务数据的成功响应（如登录返回 token）
    public static <T> R<T> ok(Integer code, String message, T data) {
        R<T> r = new R<>();
        r.setSuccess(true);
        r.setCode(code);
        r.setMessage(message);
        r.setData(data);
        r.setAccessToken(null);
        return r;
    }

    // 2. 无业务数据的成功响应
    public static R ok(Integer code, String message) {
        R<String> r = new R<>();
        r.setSuccess(true);
        r.setCode(code);
        r.setMessage(message);
        r.setData(null);
        r.setAccessToken(null);
        return r;
    }

    // 3. 失败响应
    public static R error(Integer code, String msg) {
        R r = new R();
        r.setSuccess(false);
        r.setCode(code);
        r.setMessage(msg);
        r.setData(null);
        r.setAccessToken(null);
        return r;
    }
    public static <T> R<T> ok(Integer code, String message, T data, String accessToken) {
        R<T> r = new R<>();
        r.setSuccess(true);
        r.setCode(code);
        r.setMessage(message);
        r.setData(data);
        r.setAccessToken(accessToken);
        return r;
    }
}